package com.johnson.news.activity;

import android.os.Bundle;

import com.johnson.news.R;
import com.johnson.news.databinding.ActivityAskmeReplyDetailBinding;
import com.johnson.news.model.bean.ReplyItem;
import com.johnson.news.model.remote.RemoteDataSource;
import com.johnson.news.model.util.NewsPreference;
import com.johnson.news.util.Utils;
import com.youmbe.library.BaseBindingActivity;

import io.reactivex.functions.Consumer;

public class AskmeReplyDetailActivity extends BaseBindingActivity<ActivityAskmeReplyDetailBinding> {

	
	private static final String TAG = "AskmeReplyListActivity";
	boolean fromPush;
	String itemid;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		fromPush = getIntent().getBooleanExtra("fromPush", false);
		itemid = getIntent().getStringExtra("itemid");
		String titleString = getIntent().getStringExtra("title");
		super.onCreate(savedInstanceState);

		dataBinding.replyTitleBar.setTitle(titleString);
	}
	
	@Override
	protected void onRestart() {
		super.onRestart();
		if(currentItem == null) {
			if(NewsPreference.getinstance(this).getLoginState())
				getData();
			else
				finish();
		}
	}

	@Override
	protected void init() {
		if(NewsPreference.getinstance(this).getLoginState())
			getData();
		else {
			startActivity(LoginActivity.class, null);
		}
	}

	@Override
	public int getContentViewId() {
		return R.layout.activity_askme_reply_detail;
	}

	ReplyItem currentItem;
	void getData() {
		RemoteDataSource.getRemoteDataSource()
				.getComplaintDetail(this, Utils.parseInt(itemid))
				.subscribe(new Consumer<ReplyItem>() {
					@Override
					public void accept(ReplyItem replyItem) throws Exception {
						currentItem = replyItem;
						dataBinding.setData(replyItem);
					}
				});
	}
	
}
